package com.awspaas.user.apps.cpq.controller;

import java.util.HashMap;
import java.util.Map;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.ProcessExecuteQuery;

public class CPQ_UpdatePriceStatusWeb {

	public String updatePriceStatus(UserContext userContext, String type, String bindId) {
		try {
			BO bo=new BO();
			if(type.equals("配件报价审核")) {
				BO data=SDK.getBOAPI().query("BO_EU_CPQ_AFTER_SALES").bindId(bindId).detail();
				String name=data.getString("XMMC");				
				bo.set("XMMC", name);
			}else {
				BO data=SDK.getBOAPI().query("BO_EU_CPQ_PROJECT_MSG").bindId(bindId).detail();
				String name=data.getString("XMMC");	
				String xmlx=data.getString("XMLX");	
				String cp=data.getString("CPXH");	
				String pz=data.getString("PZFA");	
				String dz=data.getString("PZFA");	
				bo.set("XMMC", name);
				bo.set("XMLX", xmlx);
				bo.set("CPXH", cp);
				bo.set("PZFA", pz);
				bo.set("PZFA", dz);
			}
			bo.set("LX", type);
			bo.set("GLBJD", bindId);
			ProcessInstance process=SDK.getProcessAPI().createProcessInstance("obj_467e59dcd1f44d0796f62b24e4faa1b8", userContext.getUID(), "");
			
			String pid=process.getId();
			SDK.getProcessAPI().setTrash(pid,false);
			SDK.getBOAPI().create("BO_EU_CPQ_APPROVAL_P", bo, pid,userContext.getUID());
		    ProcessExecuteQuery num=SDK.getProcessAPI().start(process);
		    String  taskId=SDK.getTaskQueryAPI().activityDefId("obj_20ff8016cf6e4f32a32df4f1aab9cdbf").processInstId(pid).detail().getId();		
		    SDK.getTaskAPI().setTrash(taskId,false);
		    ResponseObject ro = ResponseObject.newOkResponse();
			Map<String, String> map=new HashMap<String, String>();
			map.put("bindId", pid);
			map.put("taskId",taskId);
			ro.setData(map);
			return ro.toString();
		} catch (Exception e) {
		throw e;
		}
	
	}

}
